package com.its;

import com.its.consumer.service.api.TestService;
import com.its.provider.service.api.DemoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;

import java.net.InetAddress;
import java.net.UnknownHostException;

@DubboService
public class DemoServiceImpl implements DemoService {

    @DubboReference(group = "group1",version = "1.0", check = false)
    private TestService testService;

    @DubboReference(group = "group2",version = "2.0", check = false)
    private TestService testService2;

    private String localHost;

    public DemoServiceImpl() {
        try {
            localHost = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            localHost = "unknown host";
        }
    }

    @Override
    public String sayHello(String name) {
        try {
            Thread.sleep(5_000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        String rpcResult = testService.testHi("v1") + "." + testService2.testHi("v2");
        return rpcResult +  ". Hello " + name + ", From LocalHost: " + localHost;
    }
}
